#[derive(Debug)]
pub struct RedisConnectInfo {
    pub host: String,
    pub port: u16,
    pub password: Option<String>,
    pub db: i64,
}

impl RedisConnectInfo {
    pub fn new(host: String, port: u16, password: Option<String>, db: i64) -> Self {
        Self {
            host,
            port,
            password,
            db,
        }
    }
}

pub async fn redis_client(info: RedisConnectInfo) -> Result<redis::Client, redis::RedisError> {
    let connection_info = redis::ConnectionInfo {
        addr: redis::ConnectionAddr::Tcp(info.host, info.port),
        redis: redis::RedisConnectionInfo {
            db: info.db,
            username: None,
            password: info.password,
        },
    };

    redis::Client::open(connection_info)
}
